axios.defaults.baseURL = 'http://www.liulongbin.top:3007'
axios.interceptors.request.use(function (config) {
  if (config.url.indexOf('/my/') !== -1) {
    config.headers.Authorization = localStorage.getItem('token')
  }
  return config
}, function (error) {
  return Promise.reject(error)
})
axios.interceptors.response.use(function (response) {
  if (response.data.message === '身份认证失败！') {
    location.href = './login.html'
    localStorage.removeItem('token')
  }
  return response
}, function (error) {
  return Promise.reject(error)
})
// 封装一个格式化日期方法
function dateFormat(str) {
  let dt = new Date(str);
  let y = dt.getFullYear();
  let m = padZero(dt.getMonth() + 1);
  let d = padZero(dt.getDate());

  let HH = padZero(dt.getHours());
  let MM = padZero(dt.getMinutes());
  let SS = padZero(dt.getSeconds());

  return `${y}-${m}-${d} ${HH}:${MM}:${SS}`;
}

// 补零函数
function padZero(n) {
  return n < 10 ? '0' + n : n;
}
